﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using centrafuse.Plugins;
using System.Drawing;

namespace Altbrot.Yawr.Plugin
{
    public class UpdateProgress : CFPlugin
    {
        private string PluginName;
        private string PluginPath;
        private string PluginPathSkins;
        private string PluginPathLanguages;
        private string PluginPathIcons;
        private CFControls.CFLabel ProgressMessageLabel;
        private CFControls.CFLabel ProgressValueLabel;

        public UpdateProgress(string pluginName, ICFMain mainForm)
        {
            this.PluginName = pluginName;
            this.PluginPath = @"plugins\" + this.PluginName + @"\";
            this.PluginPathSkins = this.PluginPath + @"Skins\";
            this.PluginPathLanguages = this.PluginPath + @"Languages\";
            this.PluginPathIcons = this.PluginPath + @"Icons\";
            this.MainForm = mainForm;
        }

        public string ProgressMessage 
        {
            get
            {
                return ProgressMessageLabel.Text;
            }
            set
            {
                ProgressMessageLabel.Text = value;
                this.Invalidate(new Rectangle(ProgressMessageLabel.Bounds.X, ProgressMessageLabel.Bounds.Y, ProgressMessageLabel.Bounds.Width, ProgressMessageLabel.Bounds.Height), false);
            }
        }

        public string ProgressLevel
        {
            get
            {
                return ProgressValueLabel.Text;
            }
            set
            {
                ProgressValueLabel.Text = value;
                this.Invalidate(new Rectangle(ProgressValueLabel.Bounds.X, ProgressValueLabel.Bounds.Y, ProgressValueLabel.Bounds.Width, ProgressValueLabel.Bounds.Height), false);
            }
        }

        public override void CF_localskinsetup()
        {
            // Read the skin file, controls will be automatically created
            // CF_localskinsetup() should always call CF3_initSection() first, with the exception of setting any
            // CF_displayHooks flags, which affect the behaviour of the CF3_initSection() call.
            this.CF3_initSection("UpdateProgress");

            ProgressMessageLabel = labelArray[CF_getLabelID("LblUpdateMessage")];
            ProgressValueLabel = labelArray[CF_getLabelID("LblUpdateProgress")];
        }

        public override void CF_pluginInit()
        {
            try
            {
                // CF3_initPlugin() Will configure pluginConfig and pluginLang automatically
                // All plugins must call this method once
                this.CF3_initPlugin(this.PluginName, true);

                // All controls should be created or Setup in CF_localskinsetup.
                // This method is also called when the resolution or skin has changed.
                this.CF_localskinsetup();

            }
            catch (Exception errmsg) { CFTools.writeError(errmsg.ToString()); }
        }
    }
}
